#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
char word[21][20];
char head;
char str[10000];
int cnt[21], maxlen = -1;
int pairCnt(char STRING[], char WORD[])
{
    int l_STRING, l_WORD, i;
    l_STRING = strlen(STRING);
    l_WORD = strlen(WORD);
    int samelen = 0, ans = 0;
    for (samelen = 0; samelen <= min(l_WORD, l_STRING); samelen++)
    {
        for (i = 0; i < samelen; ++i)
        {
            if (STRING[l_STRING - samelen + i] != WORD[i])
            {
                break;
            }
        }
        if (i == samelen)
        {
            if (samelen != 0 && ans == 0)
                ans = samelen;
            else
                ans = min(ans, samelen);
        }
    }
    return ans;
}
void dfs(int x)
{
    if (cnt[x] == 0)
        return;
    int xlen = strlen(word[x]), next = -1;
    int l_STRING = strlen(str);
    int commonlen = pairCnt(str, word[x]);
    if (commonlen == 0 && l_STRING == 0 || commonlen > 0)
    {
        for (int i = 0; i <= xlen - commonlen; ++i)
        {
            str[l_STRING + i] = word[x][commonlen + i];
        }
        str[l_STRING + xlen - commonlen] = '\0';
        cnt[x]--;
    }
    maxlen = max(maxlen, (int)strlen(str));
    for (int i = 1, tlen = 0; i <= n; ++i)
    {
        if (cnt[i] == 0)
            continue;
        tlen = pairCnt(str, word[i]);
        if (tlen > 0)
        {
            dfs(i);
            str[l_STRING + xlen - commonlen] = '\0'; //回溯
            cnt[i]++;
        }
    }
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> word[i];
    }
    cin >> head;
    for (int i = 1; i <= n; ++i)
    {
        fill(cnt, cnt + n + 1, 2);
        memset(str, 0, sizeof(str));
        if (word[i][0] == head)
            dfs(i);
    }
    cout << maxlen << endl;
    return 0;
}